package com.neuedu.boot.controller;

import com.neuedu.boot.entity.User;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 项目：      springboot
 * 类名:       ValidationController
 * 创建时间：  2024/3/28 10：57
 * 描述 :
 * 作者 :     张金山
 * QQ :     314649444
 * Site:      https://jshand.gitee.io
 */
@RestController
@RequestMapping("/valid")
public class ValidationController {


    @RequestMapping("post")
    User receiveUser(@Validated User user ,  BindingResult result){
        for (FieldError fieldError : result.getFieldErrors()) {
            System.out.println("fieldError.getField() = " + fieldError.getField());
            System.out.println("fieldError.getDefaultMessage() = " + fieldError.getDefaultMessage());
        }

        return user;


    }


}
